import { InitModalMethod, ParseModalMethod } from './defination';

/**
 * 设置表单属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const initModalData = (form = {}, workstep = {}) => {
	if (!form || !workstep || !workstep.do) {
		return;
	}
	// bizSceneId
	form.bizSceneId = workstep.do?.data?.data?.data?.bizSceneId;
	// bizSceneName
	form.bizSceneName = workstep.do?.data?.data?.data?.bizSceneName;
	// isCompleted
	form.isCompleted = workstep.isCompleted;

	form.name = workstep.name;
	// groups
	form.transferGroups = workstep.do?.data?.data?.data?.groups || [];
};
InitModalMethod['sceneTransfer'] = initModalData;

/**
 * 解析表单属性
 * @param { Object } form 表单数据
 * @param { Object } workstep cached的ai工作流
 */
export const parseModalData = (form = {}, workstep = {}) => {
	console.log(form, workstep);
	if (!form || !workstep || !workstep.do) {
		return;
	}
	// bizSceneId
	workstep.do.data.data.data.bizSceneId = form.bizSceneId;
	// bizSceneName
	workstep.do.data.data.data.bizSceneName = form.bizSceneName;
	// isCompleted
	workstep.isCompleted = form.isCompleted;
	workstep.name = form.name;
	// groups
	workstep.do.data.data.data.groups = form.transferGroups;
};
ParseModalMethod['sceneTransfer'] = parseModalData;
// {
//     "robotProperty": {
//         "needHearing": "preorder",
//         "videoType": "preorder",
//         "audioType": "preorder"
//     },
//     "name": "",
//     "id": "sceneTransfer_55",
//     "no": "sceneTransfer_55",
//     "type": "bizScenTransferNode",
//     "do": {
//         "command": "send-message",
//         "data": {
//             "data": {
//                 "data": {
//                     "bizSceneId": 85,
//                     "bizSceneName": "AI工作流"
//                 },
//                 "cmd": "transfer"
//             },
//             "type": "peer-cmd"
//         },
//         "after": {
//             "command": "receive-message"
//         }
//     },
//     "answer": [
//         {
//             "do": {
//                 "data": {
//                     "reason": "quietly"
//                 },
//                 "command": "hangup"
//             },
//             "key": [
//                 "ok"
//             ],
//             "type": "ok"
//         },
//         {
//             "do": {
//                 "data": {
//                     "reason": ""
//                 },
//                 "command": "hangup"
//             },
//             "type": "reject",
//             "key": "others"
//         }
//     ],
//     "isEnd": "true",
//     "completed": true,
//     "hasStartNode": false
// }
